﻿
@{
    Layout = null;
}
<!-- 这里放模块数据!!!!!!!!!!!!!!! -->
<h1>这里放系统数据</h1>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link href="~/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" />


    <script src="~/layui-v2.6.8/layui/layui.js"></script>
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
    <div class="demoTable">
        搜索ID：
        <div class="layui-inline">
            <input class="layui-input" name="id" id="demoReload" autocomplete="off">
        </div>
        <button class="layui-btn" data-type="reload">搜索</button>
        <button class="layui-btn" data-type="Add">添加</button>
    </div>


    <table class="layui-hide" id="test" lay-filter="test"></table>
    <!--表头工具栏-->
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-danger" lay-event="getCheckData">批量删除</button>
            <button class="layui-btn layui-btn-danger" lay-event="getCheckShenpi">批量审批</button>
            <button class="layui-btn layui-btn-danger" lay-event="getCheckBohui">批量驳回</button>
            <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>

            <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
        </div>
    </script>
    <!--行操作-->
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        {{#  if(d.xint === 0){ }}
        <span style="color: green"><span> <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="edituptshi1">审批</a></span></span>
        {{#  } else { }}
        <span style="color:red">  <a class="layui-btn layui-btn-xs  layui-btn-warm" lay-event="edituptshi0">驳回</a></span>
        {{#  } }}
        <a class="layui-btn layui-btn-xs  layui-btn-danger " lay-event="del">删除</a>
    </script>
    <!--行状态-->
    <script type="text/html" id="sexTpl">
        {{#  if(d.xint === 1){ }}
        <span style="color: green"><span>已处理</span></span>
        {{#  } else { }}
        <span style="color:red">未处理</span>
        {{#  } }}
    </script>
    <!--主显示-->
    <script>
        layui.use('table', function () {
            var table = layui.table;

            table.render({
                elem: '#test'
                , url: 'http://localhost:36862/api/JuSe/XiTongShowd'
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    , layEvent: 'LAYTABLE_TIPS'
                    , icon: 'layui-icon-tips'
                }]
                , title: '用户数据表'
                , cols: [[
                    { type: 'checkbox', fixed: 'left' }
                    , { field: 'xid', title: 'ID', width: 80, fixed: 'left', unresize: true, sort: true }
                    , { field: 'xpeople', title: '操作人', width: 120, edit: 'text' }
                    , { field: 'xname', title: '菜单名称', width: 120, edit: 'text' }
                    , { field: 'xtype', title: '操作类型', width: 120, edit: 'text' }
                    , { field: 'xip', title: 'IP', width: 120, edit: 'text' }
                    , { field: 'xtime', title: '操作时间', width: 120, edit: 'text' }
                    , { field: 'xinfou', title: '日志内容', width: 120, edit: 'text' }
                    , { field: 'xint', title: '状态', width: 200, templet: '#sexTpl' }
                    , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 210 }
                ]]
                , page: true
                , limit: 7
                , limits: [1, 2, 3, 4, 5, 6, 7]
                , request:
                {
                    pageName: 'cIndex',
                    limitName: 'pSize'
                }
            });

            //头工具栏事件
            table.on('toolbar(test)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    //批量删除
                    case 'getCheckData'://批量删除
                        var data = checkStatus.data;
                        var ids = [];
                        for (let i = 0; i < data.length; i++) {
                            ids.push(data[i].xid)
                        }
                        if (confirm('确认删除' + data.length + "条数据吗?") == false) {
                            return;
                        }
                        $.ajax({
                            url: 'http://localhost:36862/api/JuSe/XTDelete?id=' + ids,
                            data: { datas: ids },
                            type: 'post',
                            success: function (d) {
                                if (d > 0) {
                                    layer.msg('成功删除' + data.length + '条数据', { time: 2000, icon: 1 }, function () {
                                        location.href = '/XiTong/XiTongShow';
                                    })
                                }
                                else {
                                    layer.msg('删除失败', { time: 2000, icon: 1 }, function () {
                                        location.href = '/XiTong/XiTongShow';
                                    })
                                }
                            }
                        })
                        break;
                    case 'getCheckLength':
                        var data = checkStatus.data;
                        layer.msg('选中了：' + data.length + ' 个');
                        break;
                    //批量操作之(批量审批)
                    case 'getCheckShenpi':
                        var data = checkStatus.data;
                        var ids = [];
                        for (let i = 0; i < data.length; i++) {
                            ids.push(data[i].xid)
                        }
                        if (confirm('确认审批' + data.length + "条数据吗?") == false) {
                            return;
                        }
                        $.ajax({
                            url: 'http://localhost:36862/api/JuSe/XTUptShi1?id=' + ids,
                            data: { datas: ids },
                            type: 'post',
                            success: function (d) {
                                if (d > 0) {
                                    layer.msg('成功审批' + data.length + '条数据', { time: 2000, icon: 1 }, function () {
                                        location.href = '/XiTong/XiTongShow';
                                    })
                                }
                                else {
                                    layer.msg('审批失败', { time: 2000, icon: 2 }, function () {
                                        location.href = '/XiTong/XiTongShow';
                                    })
                                }
                            }
                        })
                        break;
                    //批量操作之(批量驳回)
                    case 'getCheckBohui':
                        var data = checkStatus.data;
                        var ids = [];
                        for (let i = 0; i < data.length; i++) {
                            ids.push(data[i].xid)
                        }
                        if (confirm('确认驳回' + data.length + "条数据吗?") == false) {
                            return;
                        }
                        $.ajax({
                            url: 'http://localhost:36862/api/JuSe/XTUptShi0?id=' + ids,
                            data: { datas: ids },
                            type: 'post',
                            success: function (d) {
                                if (d > 0) {
                                    layer.msg('成功驳回' + data.length + '条数据', { time: 2000, icon: 1 }, function () {
                                        location.href = '/XiTong/XiTongShow';
                                    })
                                }
                                else {
                                    layer.msg('驳回失败', { time: 2000, icon: 2 }, function () {
                                        location.href = '/XiTong/XiTongShow';
                                    })
                                }
                            }
                        })
                        break;
                    case 'isAll':
                        layer.msg(checkStatus.isAll ? '全选' : '未全选');
                        break;

                    //自定义头工具栏右侧图标 - 提示
                    case 'LAYTABLE_TIPS':
                        layer.alert('这是工具栏右侧自定义的一个图标按钮');
                        break;
                };
            });
            //监听行工具事件
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                //console.log(obj)(单删)
                if (obj.event === 'del') {//删除
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            url: 'http://localhost:36862/api/JuSe/XTDelete?id=' + data.xid,
                            type: 'post',
                            success: function (d) {
                                if (d > 0) {
                                    layer.msg('删除成功', { time: 2000, icon: 1 }, function () {
                                        location.href = '/XiTong/XiTongShow'
                                    })
                                }
                                else {
                                    layer.msg('删除失败', { time: 2000, icon: 5 }, function () {
                                        location.href = '/XiTong/XiTongShow'
                                    })
                                }
                            }
                        })
                    });
                }
                //修改
                else if (obj.event === 'edit') {
                    //修改弹层
                    layer.open({
                        type: 2,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['720px', '740px'], //宽高
                        content: '/XiTong/XiTongUpt?id=' + data.xid//修改页面
                    });
                }
                //审批
                else if (obj.event === 'edituptshi1') {//状态1
                    layer.confirm('确认审批', function (index) {
                        $.ajax({
                            url: 'http://localhost:36862/api/JuSe/XTUptShi1?id=' + data.xid,
                            type: 'post',
                            success: function (d) {
                                if (d > 0) {
                                    layer.msg('审批成功', { time: 2000, icon: 1 }, function () {
                                        location.href = '/XiTong/XiTongShow'
                                    })
                                }
                                else {
                                    layer.msg('审批失败', { time: 2000, icon: 2 }, function () {
                                        location.href = '/XiTong/XiTongShow'
                                    })
                                }
                            }
                        })
                    });
                }
                //驳回
                else if (obj.event === 'edituptshi0') {//状态0
                    layer.confirm('确认驳回', function (index) {
                        $.ajax({
                            url: 'http://localhost:36862/api/JuSe/XTUptShi0?id=' + data.xid,
                            type: 'post',
                            success: function (d) {
                                if (d > 0) {
                                    layer.msg('驳回成功', { time: 2000, icon: 1 }, function () {
                                        location.href = '/XiTong/XiTongShow'
                                    })
                                }
                                else {
                                    layer.msg('驳回失败', { time: 2000, icon: 2 }, function () {
                                        location.href = '/XiTong/XiTongShow'
                                    })
                                }
                            }
                        })
                    });
                }
            });
            var $ = layui.$, active = {
                //时间查询未完善
                reload: function () {//查询
                    var demoReload = $('#demoReload');

                    //执行重载
                    table.reload('testReload', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                                id: demoReload.val()
                        }
                    });
                },
                Add: function () {
                    //页面层
                    layer.open({
                        type: 2,//这里改成2
                        skin: 'layui-layer-rim', //加上边框
                        area: ['720px', '740px'], //宽高
                        content: '/XiTong/XiTongAdd'//系统添加页面
                    });
                }
            };

            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
</body>
</html>

